aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/fund/[id]/+page.server.js
blob: c5c8db2f785c3f2e6a62024de720d7034322a5f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { error, redirect } from "@sveltejs/kit";
import { auth, get, post } from "$lib/utils";
import Qr from "qrcode-base64";

export let load = async ({ params: { id }, url }) => {
  let { amount, payments } = await get(`/fund/${id}`);

  let src = Qr.drawImg(url.href, { size: 300 });
  return { amount, payments, src };
};

export const actions = {
  default: async ({ cookies, locals, params, request }) => {
    let { user } = locals;

    if (user) {
      await post("/redeem", params, auth(cookies));
      redirect(307, `/${user.username}/payments`);
    }

    redirect(307, "/register");
  },
};